package com.wang.controller;

import com.wang.mapper.CustomerQuestionMapper;
import com.wang.pojo.CustomerFeedback;
import com.wang.pojo.CustomerQuestion;
import com.wang.pojo.CustomerRecords;
import com.wang.response.PageResult;
import com.wang.response.Result;
import com.wang.response.ResultResponse;
import com.wang.service.CustomerFeedbackService;
import com.wang.service.CustomerQuestionService;
import com.wang.service.CustomerRecordsService;
import com.wang.utils.FastDFSClient;
import io.swagger.annotations.*;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;

//@Api用在请求类上,表示对类的说明tags说明该类的作用,可以在UI界面上看到注解
//http://localhost:9002/swagger-ui/index.html#/
@RestController
@Api(tags = "客服信息管理接口")
public class CustomerController {
    @Autowired
    FastDFSClient fastDFSClient;

    @PostMapping("uploadFile")
    @Operation(summary = "fastdfs上传")
    public String uploadFile( @RequestParam("file") MultipartFile multipartFile) throws IOException {
        String upload = fastDFSClient.upload(multipartFile);
        return upload;
    }


    @RequestMapping(value = "/runerr")
    public String runError() {
        System.out.println("runError .......");

        String msg = null;
        if(msg.length()>0) {
            System.out.println("hello world");
        }

        return "index";
    }

    @Autowired
    CustomerQuestionService questionService;

    @Operation(summary = "常见问题增加")
    @PostMapping("addQuestion")
    public ResultResponse addQuestion(  @RequestBody CustomerQuestion question){
        return questionService.addQuestion(question);
    }

    @PostMapping("delQuestion/{questionId}")
    @Operation(summary = "常见问题删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "questionId",value = "问题id",dataType = "Integer",
                    paramType = "path")
    })
    public ResultResponse delQuestion( @PathVariable Integer questionId){
        return questionService.delQuestion(questionId);
    }

    @PostMapping("queryQuestion")
    @Operation(summary = "常见问题查询")
    public ResultResponse queryQuestion(@RequestBody Map<String,Object> searchMap){
        return questionService.queryQuestion(searchMap);
    }

    @Autowired
    CustomerFeedbackService feedbackService;

    @PostMapping("userFeedback")
    @Operation(summary = "用户反馈接口")
    public ResultResponse userFeedback( @RequestBody CustomerFeedback feedback){
        return feedbackService.userFeedback(feedback);
    }

    @PostMapping("queryFeedback/{pageNum}/{pageSize}")
    @Operation(summary = "反馈查询")
    public ResultResponse queryFeedback( @PathVariable Integer pageNum, @PathVariable Integer pageSize){
        return feedbackService.queryFeedback(pageNum,pageSize);
    }
    @PostMapping("respond")
    @Operation(summary = "反馈回应")
    public ResultResponse respond( @RequestBody CustomerFeedback feedback){
        return feedbackService.respond(feedback);
    }
    @Autowired
    CustomerRecordsService recordsService;

    @PostMapping("addRecord")
    @Operation(summary = "添加聊天记录")
    public ResultResponse addRecord( @RequestBody CustomerRecords records){
        return recordsService.addRecord(records);
    }

    @PostMapping("searchQuestion/{pageNum}/{pageSize}")
    @Operation(summary = "关键词与常见问题匹配")
    public PageResult<CustomerQuestion> searchQuestion( @PathVariable Integer pageNum, @PathVariable Integer pageSize, @RequestBody Map searchMap) throws IOException {
        return questionService.searchQuestion(pageNum,pageSize,searchMap);
    }

}
